package cn.jhc.db;

import java.sql.SQLException;
import org.apache.commons.dbutils.QueryRunner;
import org.h2.jdbcx.JdbcDataSource;

public class MyDbutils {

	public static void Createtable(JdbcDataSource dataSource) {
		QueryRunner run = new QueryRunner(dataSource);
       String createusersql="create table if not exists user("
       		+ "id int auto_increment primary key,"
       		+ "username varchar(255) unique ,"
       		+ "password varchar(255) not null,)";
       String createadminsql="create table if not exists admin("
          		+ "id int auto_increment primary key,"
          		+ "username varchar(255) unique ,"
          		+ "password varchar(255) not null,)";
       String creategoodssql="create table if not exists goods("
         		+ "id int auto_increment primary key,"
         		+ "goodname varchar(255),"
         		+ "price varchar(255),"
         		+ "discount varchar(255) not null,"
         		+ "factory varchar(255) unique not null ,"
         		+ "img varchar(255) not null,)";
         String createshopcarsql="create table if not exists shopcar("
        		+ "id int auto_increment primary key,"
        		+ "goodname varchar(255)  ,"
        		+ "price varchar(255) not null,"
        		+ "discount varchar(255) not null,"
        		+ "quantity varchar(255) ,"
        		+ "total varchar(255) ,"
        		+ "img varchar(255) ,"
        		+ "goodbn varchar(255) unique not null)";
       try {
    	   
		   run.update(createusersql);
		   run.update(createadminsql);
		   run.update(creategoodssql);
		   run.update(createshopcarsql);
	} catch (SQLException e) {
		e.printStackTrace();
	}
	}
    
}
